package com.example.provider_user.Controller;


import com.example.provider_user.model.UserInf;
import com.example.provider_user.wechat.UserInfDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
public class UserController {
    @Autowired
    private UserInfDao userInfDao;

    @RequestMapping("/user/getById")
    @ResponseBody
    public Object getUserById(String id) throws InterruptedException {
        System.out.println(("用户中心接口：查询用户" + id + "信息"));
        //测试超时触发降级
//        int sleepTime = new Random().nextInt(2000);
//        System.out.println(("sleepTime:" + sleepTime));
//        Thread.sleep(sleepTime);

	  //测试熔断，传入不存在的用户id模拟异常情况
//	  if (id.equals("10") ){
//	    throw new NullPointerException();
//	  }

        //测试限流,线程资源隔离,模拟系统执行速度很慢的情况
        Thread.sleep(3000);

        UserInf userInf = userInfDao.selectById(id);
//        System.out.println(userInf.toString());
        return userInf;
    }

}
